package org.catspaw.cherubim.persistence.mock.dao.mybatis;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;

import org.catspaw.cherubim.persistence.mybatis.SqlSessionFacotryUtils;

public class InitUitls {

	public static void init() throws SQLException {
		Connection conn = SqlSessionFacotryUtils.openSqlSession()
				.getConnection();
		Statement st = conn.createStatement();
		String dropTableSql = "drop table mock_person";
		try {
			st.executeUpdate(dropTableSql);
		} catch (SQLException e) {
		}
		String createTableSql = "create table mock_person(id varchar(36) primary key,name varchar(200),age int)";
		st.executeUpdate(createTableSql);
		st.close();
		String insertSql = "insert into mock_person(id,name,age) values(?,?,?)";
		PreparedStatement ps = conn.prepareStatement(insertSql);
		ps.setString(1, "1");
		ps.setString(2, "a");
		ps.setInt(3, 1);
		ps.executeUpdate();
		ps.setString(1, "2");
		ps.setString(2, "b");
		ps.setInt(3, 2);
		ps.executeUpdate();
		ps.setString(1, "3");
		ps.setString(2, "c");
		ps.setInt(3, 3);
		ps.executeUpdate();
		ps.close();
		conn.commit();
		conn.close();
	}
}
